package com.tfjybj.msg.dingmessage.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @version 1.0
 * @Description swagger配置
 * @Author 徐紫过
 * @CreateDate 2021年4月19日 19:04:10
 * @UpdateUser
 * @UpdateDate
 * @UpdateRemark
 */
//开启swagger
@EnableSwagger2
//托管spring
@Configuration
public class SwaggerConfig {

    /**
     * @description: 创建api应用
     * @author: xuziguo
     * @date: 2021/4/19 下午 7:15
     * @param: []
     * @return: springfox.documentation.spring.web.plugins.Docket
     */
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //这里采用包含注解的方式来确定要显示的接口(建议使用这种),另一种为扫描controller所在包
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * @description: 创建api的基本信息
     * @author: xuziguo
     * @date: 2021/4/19 下午 7:15
     * @param: []
     * @return: springfox.documentation.service.ApiInfo
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("msg-provider-dingmessage")
                .description("msg发送钉消息API")
                .termsOfServiceUrl("d-msg.dmsd.tech")
                .version("v1.0")
                .build();
    }
}
